import pygame
from pygame.locals import *

pygame.init()
size = width,height = 800,600
screen = pygame.display.set_mode(size)
pygame.display.set_caption("贪吃蛇游戏")
clock = pygame.time.Clock()
# 游戏循环标志变量
keep_going = True
#颜色
bg_color = (200,200,200)
# 定义格子的行列
ROW = 30
COL = 40
# 绘制网格
def draw_grid():
    # 网格的宽度和高度
    cell_width = width/COL
    cell_height = height/ROW
    # 绘制行
    for r in range(ROW):
        pygame.draw.line(screen,(0,200,100),(0,r * cell_height),
        (width,r * cell_height))
    # 绘制列
    for c in range(COL):
        pygame.draw.line(screen,(0,200,100),(c * cell_width,0),
        (c * cell_width,height))

while keep_going:
    for event in pygame.event.get():
        if event.type == QUIT:
            keep_going = False
    # 背景色填充    
    screen.fill(bg_color)

    # 绘制网格
    draw_grid()
    pygame.display.flip() # 刷新屏幕
    # 帧速率
    clock.tick(10)

pygame.quit()
import pygame
from pygame.locals import *
pygame.init()
size = width,height = 800,600
screen = pygame.display.set_mode(size)
pygame.display.set_caption("贪吃蛇游戏")
clock = pygame.time.Clock()
# 帧速率
clock.tick(10)
# 游戏循环标志变量
keep_going = True
while keep_going:
    for event in pygame.event.get():
        if event.type == QUIT:
            keep_going = False
pygame.quit
a=30
b=40
cell_width = width/b
cell_height = height/a
def draw_grid():
    # 网格的宽度和高度
    cell_width = width/b
    cell_height = height/a
    # 绘制行
    for r in range(a):
        pygame.draw.line(screen,(0,200,100),(0,r * cell_height),
                         (width,r * cell_height))
    # 绘制列
    for c in range(b):
        pygame.draw.line(screen,(0,200,100),(c * cell_width,0),
                         (c * cell_width,height))

# 绘制网格
    draw_grid()
    pygame.display.flip() # 刷新屏幕